<%--
/**
* Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
--%>
<%@page import="com.crossriver.crgis.database.service.persistence.Application_C_of_OUtil"%>
<%@page import="com.crossriver.crgis.database.model.Organisation_Information"%>
<%@ page import="com.crossriver.crgis.database.model.Application_C_of_O" %>
<%@ page import="com.crossriver.crgis.cofo.util.ApplicationCofOConstants" %>
<%@page import="com.liferay.portal.model.Country"%>
<%@page import="com.liferay.portal.service.CountryServiceUtil"%>

<%@page import="com.liferay.portal.theme.ThemeDisplay"%>
<%@taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ include file="/init.jsp"%>

<%
Organisation_Information organisation =
		(Organisation_Information)request.getAttribute(
					ApplicationCofOConstants.ORGANISATION_INFO_SESSION_ATTR);
Application_C_of_O appl = (Application_C_of_O) request.getAttribute(ApplicationCofOConstants.APPL_C_OF_O_SESSION_ATTR);
%>

<portlet:defineObjects />
<portlet:renderURL var="ApplicationCofO2">
		<portlet:param name="jspPage" value="/html/individualcofo/ApplicationCofO2.jsp" />
</portlet:renderURL>


<liferay-portlet:actionURL name="saveOrganisationInformation" var="saveOrganisationInformation"></liferay-portlet:actionURL>


 <aui:form action="<%=saveOrganisationInformation.toString() %>" method="post" name="saveOrganisationInformation_fm">

  <% String app = appl.getApplication(); %>
 <div id="main">
	<%
	if("certification".equalsIgnoreCase(app)){
	%>
	<h1>Application for Certificate Of Occupancy</h1>
	<%
	}else if("re-certification".equalsIgnoreCase(app)){
	%>
	<h1>Application for Re-Certificate Of Occupancy</h1>
	<%
	}else {
	%>
	<h1>Application for State Land</h1>
	<%
	}
	%>
	
	
  <div class="content">
  
  <liferay-ui:error key="organization-name-is-mandatory" message="organization-name-is-mandatory" />
	<liferay-ui:error key="rc-no-is-mandatory" message="rc-no-is-mandatory" />
	<liferay-ui:error key="country-of-reg-is-mandatory" message="country-of-reg-is-mandatory" />
	<liferay-ui:error key="dateofregistration-is-mandatory" message="dateofregistration-is-mandatory" />
	<liferay-ui:success key="organisation-information-save-success" message="organisation-information-save-success"></liferay-ui:success>
  
 	<table width="100%" border="0" cellpadding="0" cellspacing="0">
    	<tr>
     	<td width="15%" valign="top">
     		<aui:input name="applicationId" type="hidden" value="<%= organisation.getApplicationId() %>"></aui:input>
    		<aui:input name="buttonClicked" type="hidden" value=""></aui:input>
    		<table width="100%" id="steps" cellpadding="0" cellspacing="0">
       		<tr><td valign="middle" align="center" class="current">STEP 1</td></tr>
       		<tr><td valign="middle" align="center">STEP 2</td></tr>
	        <tr><td valign="middle" align="center">STEP 3</td></tr>
          <tr><td valign="middle" align="center">STEP 4</td></tr>
          <tr><td valign="middle" align="center">STEP 5</td></tr>
          <tr><td valign="middle" align="center">STEP 6</td></tr>
          <tr><td valign="middle" align="center">STEP 7</td></tr>
          <tr><td valign="middle" align="center">STEP 8</td></tr>                               
       	</table>
    	</td>
      <td width="85%" valign="top">
     		<table width="100%" id="mainform">
        		<tr>
        			<td class="title" colspan="3">Organisation/Company Information</td>
           </tr>
           <tr>
           	<td colspan="3" align="right" class="buttons">
            	<hr>
            	<aui:button type="button" value="Exit Application" onClick="exitApplication();"></aui:button>
			        <aui:button type="submit" value="Save" onClick="setButtonClicked('btnSave');" ></aui:button>
			        <aui:button type="submit" value="Save and Continue" onClick="setButtonClicked('btnSaveAndContinue');" ></aui:button>
							<aui:button type="button" value="Cancel Application" onClick="confirmPost()"></aui:button>
             </td>
          	</tr>
					<tr>
						<td colspan="3"><br>
					  	<aui:input type="text" 
								label="Full Name Of Organisation<span class='mandatoryfld'>*</span>"
								name="organisationName"
								value="<%= organisation.getOrganisationName() %>"
								style="width:400px; text-transform:uppercase"/> 
					  </td>
					</tr>
					<tr>
						<td colspan="3"><br>
					  	<aui:input type="text" maxlength="8" label="Registration Number (RC)<span class='mandatoryfld'>*</span>"
								value="<%= organisation.getRegNo() %>"
								name="regNo"  style="text-transform:uppercase"/> 
						</td>
					</tr>
					<tr>
						<td><br>
<%-- 	       			<aui:column columnWidth="50"> --%>
            	<aui:select style="width:130px" name="countryOfReg" label="Country" helpMessage="">
 				  			<option label="" value="---" >  </option>
                  	
	 				  		<%
	 				  		String country = "";
	 				  		if (organisation== null  
	 				  				|| organisation.getCountryOfReg() == null
	 				  				|| organisation.getCountryOfReg().equalsIgnoreCase("") ){
	 				  			
	 				  		}else{
	 				  			country = organisation.getCountryOfReg() ;
	 				  		}
	 				  		
			                List<Country> countries = CountryServiceUtil.getCountries();
			                
			                for (Country _country : countries) {
			                %> 
			                  		<aui:option selected="<%=  _country.getName().equalsIgnoreCase(country) %>" 
			                  		value="<%=_country.getName() %>"><%=_country.getName()  %></aui:option>
				 				<%
				                }
				 				%>
           		</aui:select>				  	
<%--                  </aui:column> --%>
						</td>
						<td colspan="2"><br>
							<label class="aui-field-label" for="<portlet:namespace/>dob">Registration Date<span class='mandatoryfld'>*</span></label>
							<%
							Calendar cal = CalendarFactoryUtil.getCalendar();
							if (organisation.getDateOfRegistration() != null){
								cal.setTime(organisation.getDateOfRegistration());
								//cal.setTime(individual.getDateOfBirth().getTime()));
							}
							
							Calendar current = CalendarFactoryUtil.getCalendar();
							%>	
							<liferay-ui:input-date formName="dateOfReg"  
								dayParam="dateOfRegDay"
							  dayValue="<%= cal.get(Calendar.DATE) %>"
							  disabled="<%= false %>"
							  firstDayOfWeek="<%= cal.getFirstDayOfWeek() - 1 %>"
							  monthParam="dateOfRegMonth"
							  monthValue="<%= cal.get(Calendar.MONTH) %>"
							  yearParam="dateOfRegYear"
							  yearValue="<%= cal.get(Calendar.YEAR) %>"
							  yearRangeStart="<%= current.get(Calendar.YEAR) - 200 %>"
							  yearRangeEnd="<%= current.get(Calendar.YEAR) -0  %>"
							/>
   					</td>
					</tr>
           <tr>
           	<td colspan="3"><br>
              <aui:input name="natureOfBusiness" label="Nature of Business"  type="textarea"
	             	value="<%= organisation.getNatureOfBusiness() %>"
	             	onKeyDown="limitText(this.form.limitedtextarea,this.form.countdown,180);"
	              onKeyUp="limitText(this.form.limitedtextarea,this.form.countdown,180);"
	              style="width:400px">
	           	</aui:input>
             </td>
           </tr>
           <tr>
       			<td colspan="3"><br>
               <hr>
               <p><strong>All fields asterisk in "Red" are compulsory</strong></p>
               <p>It is the applicant's responsibility to fill out the Personal Information Form.
               If a given category does not apply place the letters N/A in the space
               to indicate Not Applicable.</p>
               <p>The Personal Information Form MUST BE filled by the applicant. Your Personal 
               Information Form will be one of the main sources in determining your eligibility 
               for the award of Certificate Of Occupancy.</p>
           	</td>
   				</tr>
           <tr>
            <td colspan="3" align="right"><br>
            	<aui:button type="button" value="Exit Application" onClick="exitApplication();"></aui:button>
			        <aui:button type="submit" value="Save" onClick="setButtonClicked('btnSave');" ></aui:button>
			        <aui:button type="submit" value="Save and Continue" onClick="setButtonClicked('btnSaveAndContinue');" ></aui:button>
							<aui:button type="button" value="Cancel Application" onClick="confirmPost()"></aui:button>
						</td>
           </tr>
       	</table>
 			</td>
   		</tr>
 		</table>
	</div>
</div>
   		

  		
   	<script type="text/javascript">
	function setButtonClicked(id)
	{
	   // alert(id);
	   document.<portlet:namespace/>saveOrganisationInformation_fm.<portlet:namespace/>buttonClicked.value=id;
	  // alert(document.<portlet:namespace/>quick_add_account_fm.<portlet:namespace/>buttonClicked.value);
	    //document.getElementById('jspPage').value=id;
	}

	function selectOptions()
	{
	   // alert(id);
		
		document.<portlet:namespace/>saveOrganisationInformation_fm.<portlet:namespace/>countryOfReg.value='<%= organisation.getCountryOfReg() %>';
		document.<portlet:namespace/>saveOrganisationInformation_fm.<portlet:namespace/>countryOfReg.value='<%= organisation.getOrganisationName() %>';
		document.<portlet:namespace/>saveOrganisationInformation_fm.<portlet:namespace/>countryOfReg.value='<%= organisation.getRegNo() %>';
		document.<portlet:namespace/>saveOrganisationInformation_fm.<portlet:namespace/>countryOfReg.value='<%= organisation.getDateOfRegistration() %>';
	  
	}

	selectOptions();
	
	</script>
	 		
</aui:form>

	<liferay-portlet:actionURL name="exitApplication" var="exitApplication"></liferay-portlet:actionURL>
	<form name="<portlet:namespace/>exitApplication_fm" method="post"	id="<portlet:namespace/>exitApplication_fm" action="<%=exitApplication.toString()%>"></form>
	<script type="text/javascript">
	<!--
	function exitApplication()
	{
		document.forms["<portlet:namespace/>exitApplication_fm"].submit();
	}
	//-->
	</script>

<script type="text/javascript">
<!--
	function confirmPost()
	{
	var agree=confirm("Cancelling the process will delete the record you have entered into the portal for this application. Do you want to proceed?");
	if (agree){
		document.forms["<portlet:namespace/>deleteApplication_fm"].submit();
		return true ;
	}
	else{
		return false ;
	}
	}
//-->
</script>

<liferay-portlet:actionURL name="deleteApplication" var="deleteApplication"></liferay-portlet:actionURL>
 <aui:form action="<%=deleteApplication.toString() %>" method="post" name="deleteApplication_fm">
  	<aui:input name="applicationId" type="hidden" value="<%= organisation.getApplicationId() %>"></aui:input>
 </aui:form>
 
 